package project.a1;

import java.util.ArrayList;

/**
 * Student name : Sayaka Ozaki
 * Student ID   : 12017111
 * This is MainUI class for CP1300 A1.
 */
public class MainUI {
    private ProjModel proj;
    //private Car[] carArr;
    private static final String MENU_SET_HOR_LINES = "1";
    private static final String MENU_SET_VER_LINES = "2";
    private static final int MIN_HOR_LINES = 1;
    private static final String MENU_RUN_ONE_SIM = "5";

    public MainUI() {
        proj = new ProjModel();
    }

    public void showMenu() {
        System.out.println("=== MENU ===\n" +
                "1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n" +
                "2. Set Number of vertical lanes (V-street) [min 1, max 4]\n" +
                "3. Set Probability of a car entering H-street [min 0, max 1]\n" +
                "4. Set Probability of a car entering V-street [min 0, max 1]\n" +
                "5. Run one simulation cycle\n" +
                "6. Set and run number of simulation cycles [min 1, max 10]\n");
    }

    public void run() {
        GridView gv = new GridView(proj);
        while (true) {
            gv.show();
            showMenu();
            String choice = SimHelper.getUserInput("What is your choice?>");
            //int i = Integer.parseInt(numStr);
            //proj.setHorLaneNum(i);
            //getUserInput("Enter your choice>");
            if (choice.equals(MENU_SET_HOR_LINES)) {
                System.out.println("Your choice is " + choice + ".");
                runSetHorLines();
                //gv.show();
                //showMenu();
                gv = new GridView(proj);
            } else if (choice.equals(MENU_SET_VER_LINES)) {
                System.out.println("Your choice is " + choice + ".");
                runSetVerLines();
                gv = new GridView(proj);
            } else if (choice.equals(MENU_RUN_ONE_SIM)) {
                System.out.println("Your choice is " + choice + ".");
                runOneSim();
                gv.moveCars(1);
            }
        }
    }

    private void runOneSim() {
    }

    private void runSetVerLines() {
        String numStr = SimHelper.getUserInput("How many vertical lanes?>");
        int i = Integer.parseInt(numStr);
        if (i >= proj.getMinVerLanes() && i <= proj.getMaxVerLanes()) {
            proj.setVerLaneNum(i);
            return;
        } else {
            System.out.println("Invalid choice.\n" +
                    "Must be between" + proj.getMinVerLanes() + " and " + proj.getMaxVerLanes());
        }
    }

    private void runSetHorLines() {
        String numStr = SimHelper.getUserInput("How many horizontal lanes?>");
        int i = Integer.parseInt(numStr);
        if (i >= proj.getMinHorLanes() && i <= proj.getMaxHorLanes()) {
            proj.setHorLaneNum(i);
            return;
        } else {
            System.out.println("Invalid choice.\n" +
                    "Must be between" + proj.getMinHorLanes() + " and " + proj.getMaxHorLanes());
        }
    }
}